#!/bin/sh

pacman -S --noconfirm $(cat pkgs | sed 's #.*$  g' | tr '\n' ' ')

read -r user uspw rtpw host < confidentials

ln -sf /usr/share/zoneinfo/Europe/Bratislava /etc/localtime

hwclock --systohc



echo "sk_SK.UTF-8 UTF-8" >> /etc/locale.gen

locale-gen

echo "LANG=sk_SK.UTF-8" >> /etc/locale.conf
echo "KEYMAP=sk-qwerty" >> /etc/vconsole.conf


grub-install /dev/sda
grub-mkconfig -o /boot/grub/grub.cfg


echo "$host" > /etc/hostname
echo "127.0.0.1       localhost" >> /etc/hosts
echo "::1             localhost" >> /etc/hosts
echo "127.0.1.1       $host.localdomain $host" >> /etc/hosts


# bypass sudo password prompt
echo "%wheel ALL=(ALL) NOPASSWD: ALL" >> /etc/sudoers

useradd -m -G wheel -s /bin/bash $user


echo -e "$rtpw\n$rtpw" | passwd root


echo -e "$uspw\n$uspw" | passwd $user


systemctl enable NetworkManager dhcpcd


chown $user:$user /home/$user/user.sh

chown $user:$user /home/$user

chmod +x /home/$user/user.sh


su -c /home/$user/user.sh -s /bin/sh $user


echo -e "\nAll Done.\n\n"
